﻿using System;
using System.Configuration;
using System.Web.UI;
using System.Data;
using System.Data.SqlClient;
using mojoPortal.Web.RS.PRM.AppCode.Lib;

namespace mojoPortal.Web.RS.PRM.NewsLetter
{
    public partial class PreviewNewsLetter : Page
    {
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                int newsLetterId = 0;
                if (Request.QueryString["newsletterid"] != null)
                    newsLetterId = Convert.ToInt32(Request.QueryString["newsletterid"].ToString());

                RSUserIdentity userIdentity = new RSUserIdentity();
                litNewsLetter.Text = LoadNewLetterData(userIdentity.RSCompanyId, newsLetterId);
            }
        }


        public string LoadNewLetterData(int companyid, int newsletterid)
        {
            string data = "";
            if (companyid > 0 && newsletterid > 0)
            {
                String strSQL = "select * from rs_tblNewsLetter where newsletterid=@newsletterid and companyid=@companyid";
                SqlCommand myCommand;
                SqlParameter param;
                SqlConnection myConnection;
                myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings[RSPRMCommonFunctions.GetRSCompanyConnectionString()].ToString());
                myCommand = new SqlCommand(strSQL, myConnection);
                SqlDataReader myDataReader;

                param = new SqlParameter();
                param.SqlDbType = SqlDbType.Int;
                param.ParameterName = "@companyid";
                param.Value = companyid;
                myCommand.Parameters.Add(param);

                param = new SqlParameter();
                param.SqlDbType = SqlDbType.Int;
                param.ParameterName = "@newsletterid";
                param.Value = newsletterid;
                myCommand.Parameters.Add(param);

                myConnection.Open();
                myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
                if (myDataReader.HasRows)
                {
                    myDataReader.Read();
                    data = myDataReader["Description"].ToString();
                }

                myConnection.Close();
            }
            return data;
        }


    }
}